import AutoChart from '@/components/Echarts/AutoChart';
import { loginData } from '@/services/api';
// @ts-ignore
import { BorderBox4 } from '@jiaminghi/data-view-react';
import { useEffect } from 'react';
import { useImmer } from 'use-immer';
import './Chart7.less';

const ColumnCharts: React.FC = () => {
  const [options, setOptions] = useImmer({
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985',
        },
      },
    },
    grid: {
      top: '8%',
      left: '8%',
      right: '2%',
      bottom: '0%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        data: [],
      },
    ],
    yAxis: [
      {
        type: 'value',
      },
    ],
    series: [
      {
        color: '#8e9dff',
        name: '用户量',
        type: 'line',
        smooth: true,
        stack: 'Total',
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0.25,
                color: '#8e9dff',
              },
              {
                offset: 1,
                color: '#fff',
              },
            ],
          },
        },
        emphasis: {
          focus: 'series',
        },
        data: [],
      },
    ],
  });

  useEffect(() => {
    loginData().then((res) => {
      setOptions((draft) => {
        draft.xAxis[0].data = res.data.xData;
        draft.series[0].data = res.data.expectedData;
      });
    });
  }, []);

  return (
    <div className="chart7">
      <BorderBox4 color={['#396993', '#396993']}>
        <div className="chart7_title">登录情况</div>
        <div className="chart7_chart padding-5">
          <AutoChart option={options as any}></AutoChart>
        </div>
      </BorderBox4>
    </div>
  );
};
export default ColumnCharts;
